﻿//////////////////////////////////////////////////////////////////////////
// FileName:fmCarAccidentList.aspx
// CreateBy:DragonXiong
// CreateDate:2010-05-29
// Description:
//		   Car Accident List
//      
// Modify Log:
//	
// Copyright:
/////////////////////////////////////////////////////////////////////////
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Auto.Web.Common;
using Auto.Components;
using Model = Auto.Data.BusMan.Model;
using BLL = Auto.Data.BusMan.BLL;

namespace Auto.BusMan
{
    public partial class fmCarAccidentList : System.Web.UI.Page
    {
        DataTable dt;
        BLL.BusAccident bll = new BLL.BusAccident();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        private void InitPage()
        {

            this.ucDDLKeepDiv1.InitControl();
            Display();
        }

        #region --BindData--
        private void Display()
        {
            if (!string.IsNullOrEmpty(ucDDLKeepDiv1.SelectedValue))
            {
                dt = bll.GetList(" AND " + Model.BusAccident.FIELD_CompanyID + " ='" + ucDDLKeepDiv1.SelectedValue + "'");
            }
            else
            {
                dt = bll.GetList("");
            }
            Session["fmCarAccidentList.dt"] = dt;
            BindData();
        }

        #endregion --BindData--

        #region Event

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string startDate = txtAccidentTimeStart.CalendarDateText;
            string endDate = txtAccidentTimeEnd.CalendarDateText;
            string divID=ucDDLKeepDiv1.SelectedValue;
            string strWhere = string.Empty;

            if (!string.IsNullOrEmpty(divID))
            {
                strWhere += " AND " + Model.BusAccident.FIELD_CompanyID + " ='" + divID + "'";
            }

            if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
            {
                strWhere += " AND "+ Model.BusAccident.FIELD_AccidentTime + ">='" + startDate + "'";
                strWhere += " AND " + Model.BusAccident.FIELD_AccidentTime + "<='" + endDate + "'";
            }
            else if (!string.IsNullOrEmpty(startDate))
            {
                strWhere +=" AND " + Model.BusAccident.FIELD_AccidentTime + "='" + startDate + "'";
            }
            else if (!string.IsNullOrEmpty(endDate))
            {
                strWhere +=" AND "+ Model.BusAccident.FIELD_AccidentTime + "='" + endDate + "'";
            }
            if (!string.IsNullOrEmpty(ucBusIDFromBusIDNO1.Text))
            {
                strWhere += " AND " + Model.BusAccident.FIELD_BusID + " ='" + ucBusIDFromBusIDNO1.BusID + "'";
            }

            dt = bll.GetList(strWhere);
            Session["fmCarAccidentList.dt"] = dt;
            BindData();
        }

        #endregion Event


        #region --GridView--
        protected void BindData()
        {
            GridView1.DataSource = (DataTable)Session["fmCarAccidentList.dt"];
            GridView1.DataBind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

        }

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string docID = (string)GridView1.DataKeys[e.RowIndex].Value;
            bll.Delete(docID);
            Display();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                //BusID
                string BusID = (string)DataBinder.Eval(e.Row.DataItem, "BusID");

                BLL.BusList bllBusList = new BLL.BusList();
                Model.BusList modelBusList = bllBusList.GetModel(BusID);
                if (modelBusList != null)
                {
                    e.Row.Cells[2].Text = modelBusList.BusIdentificationNO;
                }
                else
                {
                    e.Row.Cells[2].Text = "未知车牌";
                }

                //Driver
                string driver = (string)DataBinder.Eval(e.Row.DataItem, "DriverID");

                BLL.Drivers bllDrivers = new BLL.Drivers();
                Model.Drivers modelDrivers = bllDrivers.GetModel(driver);
                if (modelDrivers != null)
                {
                    e.Row.Cells[3].Text = modelDrivers.DriverName;
                }
                else
                {
                    e.Row.Cells[3].Text = "未知姓名";
                }


            }


        }
        #endregion --GridView--

        public string CutString(object o)
        {
            if (o != null && o.ToString().Length>6)
            {
                return o.ToString().Substring(0, 6)+"...";
            }
            return o.ToString();
        }

    }

}